# -*- coding: utf-8 -*-
# @date: 2022年6月4日
# @author: shaochch
from autotest.kernel.modle import Constants

__container_dirs__ = dir({})
__container_dirs__.append('addNode')
__container_dirs__.append('setVariableLock')
__container_dirs__.append('releaseVariableLock')
__container_dirs__.append('SetVariableLock')


class VariableContainer(dict):
    """
    function:Represents a set of variables.
        Contains methods for replacing variables from list, scalars, and strings.
        On top of ${scalar}, @{list} and &{dict} variables, these methods handle
        also %{environment} variables.
    """
    def __init__(self):
        object.__setattr__(self, 'SetVariableLock', False)

    def __setattr__(self, var, value):
        if self.SetVariableLock is False:
            self[var] = value

    def __getattribute__(self, var):
        if var in __container_dirs__:
            return object.__getattribute__(self, var)
        return self[var]

    def addNode(self, var):
        if var not in self:
            self.__setattr__(var, VariableContainer())

    def setVariableLock(self):
        self['SetVariableLock'] = True

    def releaseVariableLock(self):
        self['SetVariableLock'] = False


Var = VariableContainer()
Var.addNode('Project')
Var.addNode('Case')
Var.addNode('Suite')
Var.addNode('Config')

# 定义工程的一些属性，并赋予默认值
Var.Project.StartTime = 0
Var.Project.EndTime = 0
Var.Project.CostTime = 0
Var.Project.RootPath = None
Var.Project.TaskId = None
Var.Project.ReportPath = None
Var.Project.Total = 0
Var.Project.Passed = 0
Var.Project.Failed = 0
Var.Project.Block = 0
Var.Project.NotRun = 0

# 定义用例的一些属性，并赋予默认值
Var.Case.CaseID = None
Var.Case.CaseResult = Constants.CASE_NOT_RUN
Var.Case.CaseName = None
Var.Case.StartTime = 0
Var.Case.EndTime = 0
Var.Case.Module = None
Var.Case.Marker = None
Var.Case.Desc = ""
Var.Case.Detail = ""


if __name__ == '__main__':
    pass
